package com.system.manager.modules.development.controller;


import com.system.manager.common.annotation.PreAuthorize;
import com.system.manager.common.entity.Result;
import com.system.manager.modules.authorized.enums.SubjectType;
import com.system.manager.modules.development.entity.DevePurchase;
import com.system.manager.modules.development.entity.DeveRecord;
import com.system.manager.modules.development.service.IDevePurchaseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author yxp
 * @since 2021-11-17
 */
@Api(tags = "采购API")
@RestController
@RequestMapping("/development/deve-purchase/")
public class DevePurchaseController {

    @Autowired
    private IDevePurchaseService devePurchaseService;

    @ApiOperation("新建采购报告")
    @PreAuthorize(SubjectType.PROJECT_LEADER)
    @PostMapping("insert/purchase")
    public Result insertPurchase(@RequestBody   DevePurchase devePurchase){
        try {
            devePurchaseService.insertPurchase(devePurchase);
            return Result.ok();
        }catch (Exception e){
            e.printStackTrace();
            return Result.error();
        }
    }
    @ApiOperation("删除采购报告")
    @PreAuthorize(SubjectType.PROJECT_LEADER)
    @GetMapping("delete/purchase")
    public Result deletePurchase(Integer id){
        try{
            devePurchaseService.deletePurchase(id);
            return Result.ok();
        }catch (Exception e){
            e.printStackTrace();
            return Result.error();
        }
    }
    @ApiOperation("查找采购报告")
    @PreAuthorize(SubjectType.PROJECT_LEADER)
    @GetMapping("select/purchase")
    public Result selectAllPurchase(@RequestParam(name = "page", required = false, defaultValue = "1")Integer page,
                                  @RequestParam(name = "limit", required = false, defaultValue = "10")Integer size,
                                  @RequestParam(name = "id",required = false) Integer id){
        try{
            Result result =  devePurchaseService.selectAllPurchase(page,size,id);

            return result;
        }catch (Exception e){
            e.printStackTrace();
            return Result.error();
        }
    }


}
